import fileAxios from 'axios'
fileAxios.defaults.baseURL='';
fileAxios.defaults.headers['Content-Type']='multipart/form-data;charset=UTF-8';
fileAxios.defaults.timeout=100000;
fileAxios.interceptors.request.use(req=>{
    let token=sessionStorage.getItem('token');
    token && (req.headers['token']=token);
    return req;
},err=>{
    return Promise.reject(err);
})

fileAxios.interceptors.response.use(res=>{
    res.data.token && sessionStorage.setItem('token',res.data.token);
    return res;
},(err)=>{
    switch(err.response.status){
        case 401:
            sessionStorage.removeItem('token');
            window.location.href='/home';
    }
    return Promise.reject(err);
})
export default fileAxios;